//
//  RuleDetailsViewController.m
//  smarthings
//
//  Created by Stefan Tsvyatkov on 10/28/14.
//  Copyright (c) 2014 Stefan Tsvyatkov. All rights reserved.
//

#import "RuleDetailsViewController.h"

@interface RuleDetailsViewController ()

@property (weak, nonatomic) IBOutlet UITableViewCell *nameCell;

@end

@implementation RuleDetailsViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Rule's Name" message:@"Please enter rule's name" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
            alert.alertViewStyle = UIAlertViewStylePlainTextInput;
            [alert addButtonWithTitle:@"OK"];
            alert.tag = 0;
            [alert show];
            [tableView deselectRowAtIndexPath:indexPath animated:YES];
        }
    }
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 0) {
        if (buttonIndex == 1) {
            self.nameCell.detailTextLabel.text = [alertView textFieldAtIndex:0].text;
        }
    }
}

@end
